#include "ReceiveFile.h"
#include "ui_ReceiveFile.h"
#include <QFileDialog>
#include <QFile>

extern QString gfileName;
extern QString gfileData;

ReceiveFile::ReceiveFile(QWidget *parent)
	: BasicWindow(parent)
{
	ui = new Ui::ReceiveFile();
	ui->setupUi(this);
	initTitleBar();
	setTitleBarTitle("发送文件", ":/Resources/MainWindow/qqlogoclassic.png");
	loadStyleSheet("ReceiveFile");
	//setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
}

ReceiveFile::~ReceiveFile()
{
	delete ui;
}

void ReceiveFile::setMsg(QString & a)
{
	ui->label->setText(a);
}

void ReceiveFile::on_cancelBtn_clicked()
{
	emit refuseFile();

	close();
}

void ReceiveFile::on_okBtn_clicked()
{

	QString path = QFileDialog::getExistingDirectory(
		this,
		"选择路径",
		"/"
	);

	QString fileName = path + "/" + gfileName;

	QFile file(fileName);

	if (file.open(QIODevice::WriteOnly))
	{
		file.write(gfileData.toUtf8());

		file.close();
	}
	else
	{
		
	}

	close();
}
